<?php

namespace app\api\controller;
use app\api\model\FunDubbing;
use app\api\model\FunDubbingSentences;
use app\common\controller\Api;
use think\Request;

class Fun extends Api
{
    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = [];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    private $base;

    private $child;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);

        $this->base = new FunDubbing();
        $this->child = new FunDubbingSentences();
    }

    public function getList()
    {
        $limit = request()->get('limit', 10);
        $page = request()->get('page', 1);

        $list = $this->base->limit($limit)->page($page)->select();

        $this->success(null, $list);
    }

    public function getInfo()
    {
        $versionId = request()->get('versionId', null);
        if (!$versionId)
            $this->error("参数有误");

        $baseInfo = $this->base->where([
            'versionId' => $versionId
        ])->find();

        $childInfo = $this->child->where([
            'parentVersionId' => $versionId
        ])->select();

        $this->success(null, [
            'base' => $baseInfo,
            'child' => $childInfo
        ]);
    }
}